package com.xuhuan.juc.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @Author huan.xu
 * @Date 2021/12/28 22:40
 * @Description 多线程8锁
 */
public class Lock8 {
    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();
        Phone phone2 = new Phone();
        new Thread(() -> {
            phone.sendEmail();
        }, "A").start();
        Thread.sleep(200);
        new Thread(() -> {
            phone2.sendSms();
        }, "B").start();
    }
}

@Slf4j
class Phone {
    public static synchronized void sendEmail() {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("邮件");
    }

    public static synchronized void sendSms() {
        log.info("短信");
    }

}